package de.wellenblau.slideshow
{
	import caurina.transitions.Tweener;
	
	import flash.display.Bitmap;
	
	public class FadeInOutSlideshow extends AbstractSlideshow
	{
		
		//tweenConfig
		private var _fadeInTime:uint;
		private var _fadeInDelay:Number;
		private var _fadeInTransition:String;
		private var _fadeOutTime:uint;
		private var _fadeOutDelay:Number;
		private var _fadeOutTransition:String;
		
		//config especially for this fade or tween
		private var _currentImage:Bitmap;
		
		public function FadeInOutSlideshow()
		{
			super();
		}
		
		override protected function initConfig():void{
			//faderconfig
			_fadeInTime = _config.fadein.@time;
			_fadeInDelay = _config.fadein.@delay;
			_fadeInTransition = _config.fadein.@transition;
			_fadeOutTime = _config.fadeout.@time;
			_fadeOutDelay = _config.fadeout.@delay;
			_fadeOutTransition = _config.fadeout.@transition;
		}
		
		
		override protected function loadingComplete():void{
			//add the current image to the que
			if(_currentImage != null)_images.push(_currentImage);
			//shift the next image out of the que
			_currentImage = _images.shift();
			//dispaly the current image
			addChild(_currentImage);
				
			Tweener.addTween(
				_currentImage, //fade in the current image
				{
					alpha:1, 						//make it visable
					time:_fadeInTime,				//tweentime
					delay:_fadeInDelay,				//how long should the current image stay invisable
					transition:_fadeInTransition, 	//which transition
					onComplete:function():void{		//what happend after the fade in -> the fade out ;)
						Tweener.addTween(
							_currentImage, //fade out the current image
							{
								alpha:0,						//make it invisable
								time:_fadeOutTime,				//tweentime
								delay:_fadeOutDelay,			//how long should the current image stay visable
								transition:_fadeOutTransition,	//which transition
								onComplete:function():void{		// after the fade out -> fade in the next image
									loadingComplete();
								}
							}
						);			
					}
				}
			);
			
			//Tween end
		}
		
	}
}